module SandBox
  include DrunkenMaster
  
  # Demo application that demonstrates some stuff
  class Application < View

    def self.be_plugged router
      doc_files_handler = DrunkenMaster::FileHandler.new(File.dirname(__FILE__)+'/../../drunkenMaster/doc')
      
      router.plug public_files_handler,  '/'
      router.plug self,                   '/'
      router.plug TerminalWidget,         '/terminal'
      router.plug doc_files_handler,      '/documentation'
    end    
        
    def self.public_files_handler
      DrunkenMaster::FileHandler.new(File.dirname(__FILE__)+'/public')
    end

    
    def render
      context.page.title.innerHTML = 'SandBox Demo featuring ext js'
      context.page.link_css '/css/desktop.css'
      context.page.link_css '/resources/css/ext-all.css'
      context.page.link_css '/screen.css'
      context.page.link_js '/ext.js'
      context.page.link_js '/js/App.js'
      context.page.link_js '/js/Desktop.js'
      context.page.link_js '/js/Module.js'
      context.page.link_js '/js/StartMenu.js'
      context.page.link_js '/js/TaskBar.js'
      context.page.link_js '/sample.js'

      e :div, :id => "x-desktop" do
        e nil, '<a href="http://extjs.com" target="_blank" style="margin:5px; float:right;"><img src="images/powered.gif" /></a>'
        e :dl, :id => 'x-shortcuts' do
          add Shortcut.new(
            'Documentation',
            :className => 'documentation',
            :onclick => DocumentationWindow.new.open_js
          )
          add Shortcut.new(
            'Demo', 
            :className => 'demo_browser',
            :onclick => DemoWindow.new.open_js
          )
          add Shortcut.new('Code', :className => 'code_browser')
          add Shortcut.new(
            'Console',
            :className => 'console',
            :onclick => TerminalWindow.new.open_js
          )          
          note = StickyNote.new
          note.context = context
          add Shortcut.new(
            'Notes',
            :className => 'console',
            :onclick => note.open_js
          )
          add Shortcut.new(
            'Statistics',
            :className => 'statistics',
            :onclick => StatisticsWindow.new.open_js
          )
          
        end
      end
      
      e :div, :id => 'ux-taskbar' do
        e :div, :id => 'ux-taskbar-start'
        e :div, :id => 'ux-taskbuttons-panel'
        e :div, :id => 'x-clear'        
      end
      
      super()
    end
  end
  
end